package com.qf.servlet;

import com.qf.entity.Admin;
import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet(urlPatterns = "/headershow")
public class HeaderShowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Admin admin =(Admin) req.getSession().getAttribute("login_user");
        String header = admin.getHeader();
        System.out.println("----》获取用户头像的名称：" +header);

        //头像的File 对象
        File file =new File(RegisterFileServlet.uploadedPath+header);
        try (
                InputStream in = new FileInputStream(file);
                OutputStream out = resp.getOutputStream();
                ){
            IOUtils.copy(in,out);
        }
    }
}
